package com.zxkj.commonpatrol.utils;

import android.content.Context;
import android.content.res.AssetManager;
import android.util.Log;

import com.czy.basecommon.utils.constant.ItrackConstant;
import com.czy.basecommon.utils.global.ItrackApp;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;

public class LocalDataUtils {

    public static void creatGuideVideo(Context context) {

        new Thread() {
            public void run() {
                try {

                    File path_file = new File(ItrackConstant.Video);
                    if (!path_file.exists()) {
                        try {
                            path_file.mkdirs();
                        } catch (Exception e) {

                        }
                    }

                    long start = System.currentTimeMillis();

                    //第二个参数是生成的文件的名字（包括后缀名），一般和assets文件中要打开的一致
                    File file = new File(ItrackConstant.Video, "video1.mp4");
                    if (!file.exists()) {
                        AssetManager assetManager = context.getAssets();// 获取asset管理者
                        InputStream in = null;
                        FileOutputStream out = null;
                        try {
                            //assets文件中要打开的文件的名字（包括后缀名）
                            in = assetManager.open("video1.mp4");
                            out = new FileOutputStream(file);
                            byte[] b = new byte[1024];
                            int len = -1;
                            while ((len = in.read(b)) != -1) {
                                out.write(b, 0, len);
                            }
                        } catch (IOException e) {
                            e.printStackTrace();

                        } finally {
                            if (out != null) {
                                out.close();
                            }
                            if (in != null) {
                                in.close();
                            }

                        }
                    }
                    long end = System.currentTimeMillis();
                    Log.e("创建视频引导页播放视频用时===", "" + (end - start));

                } catch (Exception e) {

                }
            }
        }.start();

    }

}
